package com.xiaoshuidi.cloud.module.rooms.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomDoorlockCdkeyMappingMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomDoorlockCdkeyMapping;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author Feng
 * @date 2023/9/27
 */
@Repository
public class RoomDoorlockCdkeyMappingRepository extends ServiceImpl<RoomDoorlockCdkeyMappingMapper, RoomDoorlockCdkeyMapping> {

    /**
     * 根据门锁激活码配置ID 删除关联关系
     *
     * @param cdkeyId
     * @return
     */
    public boolean removeByCdkeyId(Long cdkeyId) {
        LambdaQueryWrapper<RoomDoorlockCdkeyMapping> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomDoorlockCdkeyMapping::getCdkeyId, cdkeyId);
        boolean b = this.remove(wrapper);
        return b;
    }

    /**
     * 根据门锁激活码配置ID 查询关联房源
     *
     * @param cdkeyId
     * @return
     */
    public List<RoomDoorlockCdkeyMapping> listByCdkeyId(Long cdkeyId) {
        LambdaQueryWrapper<RoomDoorlockCdkeyMapping> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomDoorlockCdkeyMapping::getCdkeyId, cdkeyId);
        return this.list(wrapper);
    }

    /**
     * 根据门锁激活码配置ids 查询关联房源
     *
     * @param cdkeyIds
     * @return
     */
    public List<RoomDoorlockCdkeyMapping> listByCdkeyIds(List<Long> cdkeyIds) {
        LambdaQueryWrapper<RoomDoorlockCdkeyMapping> wrapper = Wrappers.lambdaQuery();
        wrapper.in(RoomDoorlockCdkeyMapping::getCdkeyId, cdkeyIds);
        return this.list(wrapper);
    }

    /**
     * 根据房间ID 获取配置关联
     *
     * @param roomId
     * @return
     */
    public RoomDoorlockCdkeyMapping getByRoomId(Long roomId) {
        LambdaQueryWrapper<RoomDoorlockCdkeyMapping> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomDoorlockCdkeyMapping::getRoomHouseId, roomId);
        return this.getOne(wrapper);
    }
}
